/**
 * MIT License
 *
 * Copyright (c) 2024 lishengbo
 * Email: 397237738@qq.com
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.cobertura.test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class FileWriteUtil {
    private static String openCoberturaClasses="open-cobertura-classes";
    /**
     * 写入探针数据到文件系统，权用于测试使用
     * @param className
     * @param probeData
     */
    public static void writeCoberturaData(long id,String className,boolean[] probeData){
        String filePath = "coberturaData.cob"; // 替换为实际文件路径
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(getExecOutPath()+"/"+filePath));
            String data=Arrays.toString(probeData);
            writer.write(id+","+className+","+data);
            writer.newLine(); // 换行
            writer.close();
            System.out.println("文件写入成功");
        } catch (IOException e) {
            System.out.println("文件写入失败: " + e.getMessage());
        }
    }

    public static String getExecOutPath(){
        // 获取Maven项目的根目录
        String baseDir = System.getProperty("user.dir");
        // 获取Maven构建输出目录
        String targetDir = System.getProperty("project.build.directory", "target");
        // 合并根目录和构建输出目录得到完整的target路径
        String targetPath = baseDir + "/";
//        String path=targetPath+"/";
        return targetPath;
    }
}
